const app = new Vue({
    el: '#app',
    data: {
        sysLogin: new SysLogin(),
        isVerify: false,
        codeImgUrl: '/system/get-code',
        codeImgRequestUrl: '/system/get-code',
    },
    methods: {
        checkSysUser() {
            const {loginName, password, code} = this.sysLogin
            if (!loginName) {
                rxPrompt.msg('用户名不能为空')
                return false
            }
            if (!password) {
                rxPrompt.msg('密码不能为空')
                return false
            }
            if (!code && this.isVerify) {
                rxPrompt.msg('验证码不能为空')
                return false
            }
            return true
        },
        async login() {
            if (!this.checkSysUser()) {
                return
            }
            try {
                const res = await sysLoginApi.login(this.sysLogin)
                const {code, msg} = res
                if (code !== 200) {
                    rxPrompt.msg('登录失败：' + msg)
                    this.refresh();
                    return
                }
                await rxPrompt.msg('登录成功，即将跳转到首页')
                sysMenuApi.loadSysMenuList.clear()
                sysLoginApi.currentUser.clear()
                location.href = '/'
            } catch (e) {
                rxPrompt.msg('登录失败，用户名或密码错误')
                this.refresh();
            }

        },
        refresh() {
            this.codeImgUrl = this.getVerifyCodeUrl();
        },
        getVerifyCodeUrl() {
            return this.codeImgRequestUrl + '?time=' + new Date().getTime();
        },
    },
    computed: {},
    async mounted() {
    },
})